﻿@model Tuple<List<PinBoardDashBoardModel>, int>

<div class="modal-dialog modal-wide" tabindex="10">
    <form action="/Post/Edit" method="POST" id="editArticleForm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                @*<h4 class="modal-title tahomaFont">در حال ویرایش @Model.Title</h4>*@
            </div>
            <div class="modal-body">
                <input type="hidden" name="Id" value="@Model.Item2" />

                <div class="row">
                    @foreach (var item in this.Model.Item1)
                    {
                        var id = Guid.NewGuid().ToString();
                        <div class="col-sm-4">
                            
                            <label for="@id">
                                <span class="btn btn-success">
                                    <input type="checkbox" id="@id" class="boarditem" data-id="@item.Id">
                                    <img class="img-responsive" src="~/Content/assets/img/tmb-c.png" />
                                </span>

                            </label>
                            <div class="footer tahomaFont" style="text-align:center;">
                                @item.Title
                            </div>
                        </div>
                    }
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn red" data-dismiss="modal" >لغو</button>
                <input type="submit" class="btn green" id="saveButton" value="ثبت" data-pinId="@Model.Item2" />
            </div>
            <div>
                <hr />
            </div>
        </div>
    </form>
</div>


<script>
    $('#saveButton').click(function (e) {
        e.preventDefault();
        var button = $(this);
        var id = button.attr('data-pinId');
        var ids = new Array();
        
        $('.boarditem').each(function (i, e) {
            if($(this).is(':checked'))
            {
                ids.push($(this).attr('data-id'));
            }
        });

        if (ids.length < 1)
        {
            alert('need to choose atleast one board');
            return false;
        }

        $.ajax({
            type: 'POST',
            url: '/ImagePin/Repin',
            data: {
                pinId: id,
                boardIds: ids
            },
            success: function (data) {
                alert('done');
            }
        })
    });

</script>